package com.rd.student.jiaji.class4.suyan.zrrd.Study;

public class StudengTest {
    public static void main(String[] args) {
        //定义一个为20的Student数组
        Student[] students=new Student[20];
        //使用循环，给数组的元素赋值
        for (int i=0;i<students.length;i++){
            students[i]=new Student();
            //给每一个学生对象的number state score属性赋值
            students[i].number=i+1;
            students[i].state=(int)(Math.random()*6+1);
            students[i].score=(int)(Math.random()*101);
        }
        //打印除3年级的学生信息
        for (int i=0;i<students.length;i++){
            if (3==students[i].state){
               Student stu=students[i];
//                System.out.println("number:"+stu.number+"state:"+stu.state+"score:"+stu.score);
                System.out.println(stu.showinfo());
            }
        }
        System.out.println("--------------");
        //使用冒泡排序安学生的成绩排序，并遍历学生数组
        for (int i=0;i<students.length;i++){
            System.out.println(students[i].showinfo());
        }
        for (int i=0;i<students.length-1;i++){
            for (int j=0;j<students.length-1-i;j++){
                if (students[j].score>students[j+1].score){
                    Student temp=students[j];
                    students[j]=students[j+1];
                    students[j+1]=temp;
                }
            }
        }
        System.out.println("-------");
        for (int i=0;i<students.length;i++){
            System.out.println(students[i].showinfo());
        }
    }


}
